package com.example.core.arch.interceptor;

import org.slf4j.MDC;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;

@Component
public class LogTraceInterceptor implements HandlerInterceptor {

    private static final String TRACE_ID = "traceRootId";

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        MDC.remove(TRACE_ID);
        MDC.put(TRACE_ID, UUID.randomUUID().toString());
        return true;
    }
}

